﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Dzzzr.DataLayer;

namespace Dzzzr
{
  public partial class MarkerInfo
  {
    public static MarkerInfo GetMarkerInfo(int gameID, int entityID)
    {
      MarkerInfo marker = null;
      using (SqlConnection cnn = Helper.Connection)
      {
        SqlCommand cmd = new SqlCommand("GetMarkerInfo", cnn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@GameID", gameID);
        cmd.Parameters.AddWithValue("@EntityID", entityID);
        SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        if (rd.Read())
        {
          marker = new MarkerInfo();
          marker.ID = rd.GetInt32(0);
          marker.Name = rd.GetString(1);
          marker.Description = rd.GetString(2);
          marker.Latitude = rd.GetDouble(3);
          marker.Longitude = rd.GetDouble(4);
          marker.Time = rd.GetDateTime(5);
          marker.Speed = rd.IsDBNull(6)? new Nullable<double>() : new Nullable<double>(rd.GetDouble(6));
          marker.Altitude = rd.IsDBNull(7) ? new Nullable<double>() : new Nullable<double>(rd.GetDouble(7));
          marker.Delay = rd.IsDBNull(8) ? new Nullable<double>() : new Nullable<double>(rd.GetInt32(8));
        }
      }
      return marker;
    }

  }
}
